/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao.metadata.impl;

import com.altuure.yagdao.metadata.MetamodelPropertyDescriptor;
import org.apache.commons.beanutils.MappedPropertyDescriptor;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
public class MetamodelPropertyDescriptorImpl extends PropertyDescriptor implements MetamodelPropertyDescriptor,Comparable {
    private String name;
    private boolean isCollection;
    private Class type;
    private boolean isVersion;
    private boolean isId;
    private Class targetType;
    private MappingType mappingType;
    private BindType bindType;

    public MetamodelPropertyDescriptorImpl(String propertyName, Class<?> beanClass) throws IntrospectionException {
        super(propertyName, beanClass);    //To change body of overridden methods use File | Settings | File Templates.
    }

   

    public int compareTo(Object o) {
        if (!(o instanceof MetamodelPropertyDescriptorImpl)) {
            throw new IllegalArgumentException("sss");
        }
        MetamodelPropertyDescriptorImpl d= (MetamodelPropertyDescriptorImpl) o;
        if(isId!=d.isId)
            return (isId)?-1:1;

        return name.compareTo(d.name);
    }

    public PropertyDescriptor getPropertyDescriptor() {
        return this;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isCollection() {
        return isCollection;
    }

    public void setCollection(boolean collection) {
        isCollection = collection;
    }

    public Class getType() {
        return type;
    }

    public void setType(Class type) {
        this.type = type;
    }

    public boolean isVersion() {
        return isVersion;
    }

    public void setVersion(boolean version) {
        isVersion = version;
    }

    public boolean isId() {
        return isId;
    }

    public void setId(boolean id) {
        isId = id;
    }

    public Class getTargetType() {
        return targetType;
    }

    public void setTargetType(Class targetType) {
        this.targetType = targetType;
    }

    public MappingType getMappingType() {
        return mappingType;
    }

    public void setMappingType(MappingType mappingType) {
        this.mappingType = mappingType;
    }

    @Override
    public String toString() {
        return "MetamodelPropertyDescriptorImpl{" +
                "name='" + name + '\'' +
                ", isCollection=" + isCollection +
                ", type=" + type +
                ", isVersion=" + isVersion +
                ", isId=" + isId +
                ", targetType=" + targetType +
                ", mappingType=" + mappingType +
                '}';
    }

    public void setBindType(BindType bindType) {
        this.bindType = bindType;
    }

    public BindType getBindType() {
        return bindType;
    }
}
